package com.company.indicationshots.util;

import static androidx.core.content.ContextCompat.getSystemService;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
//软键盘弹出事件
public class EditTextClick {
    //批量设置点击输入框获得焦点并弹出软键盘
    @SuppressLint("ClickableViewAccessibility")
    public static void setEditTextClickListener(final EditText editText, Context context) {
        editText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    editText.setFocusable(true);
                    editText.setFocusableInTouchMode(true);
                    editText.requestFocus();
                    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
                    return true; // 消耗这个事件，防止它继续传播
                }
                return false;
            }
        });
    }
}
